package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author：徐志荣
 * @Date：2023/7/9 上午 9:27
 */

@RestController

public class RedisController {

    //1. 引入 redis模板 (redis 本身)
    //StringRedisTemplate 不仅仅有string 还有list hash set zset

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/set")
    public String setRedis(){
        //redis 写缓存操作
        stringRedisTemplate.opsForValue().set("username","zhangsan");
        return "redis 存储成功";
    }

    @RequestMapping("/get")
    public String getRedis(){
        //redis 读缓存操作
        String result = stringRedisTemplate.opsForValue().get("username");
        return result;
    }


}
